import { CommandContext } from "./command.context";
import { BaseContext } from "p-elite-app-contextbroker";

export class IQnsOption {
    sync?: boolean;
    incremental?: boolean;
    filterNonBOFields?: boolean;
    maxRecord?: number;
    timeout?: number;
    throttle?: number;
    /**these three are pageQuery */
    pageSize?: number;
    pageCacheSize?: number;
    prefetchWaterMark?: number;
    /**if true and command is sub or qns ,then when reconnect from pilot ,will resubject this topic */
    autoReSubType: string;
}

export class QNSContext extends CommandContext {
    query: string;
    sync?: boolean;
    incremental?: boolean;
    filterNonBOFields?: boolean;
    maxRecord?: number;
    timeout?: number;
    throttle?: number;

    /**these three are pageQuery */
    pageSize?: number;
    pageCacheSize?: number;
    prefetchWaterMark?: number;

    /**if true and command is sub or qns ,then when reconnect from pilot ,will resubject this topic */
    autoReSubType?= AutoReSubTypeQNS;
    useBatchModel? = false;
}

export class ProxyInvokeContext extends CommandContext {
    command = commandTypeProxyInvoke;
    className: string;
    methodName?: string;
    arguments: Array<any>;
    proxyId?: string;
    region?: string;
    domain?: string;
}

export class ProxyLoginCommandContext extends CommandContext {
    command = commandTypeProxyLogin;
    className: string;
    region?: string;
    domain?: string;
}

export class ProxyLogoutCommandContext extends CommandContext {
    command = commandTypeProxyLogout;
    proxyId:string;
}

export class RemoteProxyInvokeContext extends CommandContext {
    command = commandTypeRemoteProxyInvoke;
    className: string;
    methodName?: string;
    arguments: Array<any>;
    proxyId?: string;
    region?: string;
    domain?: string;
    newProxyInstance:boolean;
}
export class HandleHandshakeContext extends BaseContext {
    loginInfo: Map<string, any>;
}

export class ConnectToPilotContext extends BaseContext {
    url?: string;
    token?: string;
}

export class ConnectedPilotContext extends BaseContext {
}

export class PilotWebSocketErrorContext extends BaseContext {
    error: string;
}

export class CancelSubCommandContext extends CommandContext {
    command = commandTypeUnSubScribe;
    requestId: string;

    constructor(requestId: string) {
        super();
        this.requestId = requestId;
    }
}

export class PilotFuncInvokeContext extends BaseContext {
    methodName?: string;
    arguments: Array<any>;
    uuid: string;
}

export class PilotFuncResultContext extends BaseContext {
    result: any;
    uuid: string;
    error?:any;
}

export class LoginToPilotContext extends BaseContext {
    loginParam?:LoginParam;
    loginResponse?:any;
    error?:any
}

export class PublishBOContext extends CommandContext {
    command = commandTypePublish;
    requestId: string;
    payload:any;
    messageDefinition:string;
}


export interface LoginParam{
    url:string;
    username:string;
    password:string;
    authnType?:string;
    lifeTime?:string;
}


export const commandTypeOnlyQuery = 'query';
export const commandTypeOnlySubscribe = 'subscribe';
export const commandTypeQueryAndSubScribe = 'qns';
export const commandTypePageQuery = 'PageQuery';
export const commandTypeProxyInvoke = 'ProxyInvoke';
export const commandTypeProxyList = 'ProxyList';
export const commandTypeMsgDefList = 'MsgDefList';
export const commandTypePageControlResponse = 'PageControlResponse';
export const commandTypeProxyLogin = 'ProxyLogin';
export const commandTypeProxyLogout = 'ProxyLogout';
export const commandTypeRemoteProxyInvoke = 'RemoteInvoke';
export const commandTypeUnSubScribe = 'unsubscribe';
export const commandTypePublish = 'Publish';

export const AutoReSubTypeQNS = 'AutoReSubTypeQNS';
export const AutoReSubTypeSub = 'AutoReSubTypeSub';
export const AutoReSubTypeNone = 'AutoReSubTypeNone';